package com.google.code.netbuilder.dal.providersimpl;

import com.google.code.netbuilder.dal.entities.Cable;
import java.sql.SQLException;
import java.util.List;

import com.google.code.netbuilder.dal.entities.Wire;
import com.google.code.netbuilder.dal.providers.IWireProvider;
import com.google.code.netbuilder.dal.services.JPAServise;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;

public class WireProviderJPA implements IWireProvider {
    
        private static EntityManager em = JPAServise.getEntityManager();
        private static EntityTransaction trans = em.getTransaction();

	@Override
	public void save(Wire entity) {
                trans.begin();
                em.persist(entity);
                trans.commit();
	}

	@Override
	public void update(Wire entity) {
                trans.begin();
                em.merge(entity);             
                trans.commit();
	}

	@Override
	public void delete(Wire entity) {
                trans.begin();
                em.remove(entity);             
                trans.commit();
	}

	@Override
	public List findAll() {
                Query query = em.createQuery("SELECT w FROM Wire w");
                return (List<Wire>) query.getResultList();
	}

	@Override
	public Wire findByID(Integer id) {
		return em.find(Wire.class, id);
	}

}
